import { Config } from "../../Config"
import { BigEvolution, BigState } from "../core/Big"
import { Player } from "../core/Player"
import { Terrain } from "../core/Point"
import Utils from "../GameUtils"
import { BaseHandler } from "./BaseHandler"

export class 地灵Handler extends BaseHandler{

    /** 大子移动 */
    move(data:any,player:Player) {
        this.handlerMgr.spendAction(player,Config.COST_BIG_MOVE)
        let startPoint = this.gameMgr.map_point.get(data.start)
        let endPoint = this.gameMgr.map_point.get(data.end)
        let big_start = startPoint.big
        big_start.actionOnce()
        let big_end = endPoint.big
        if(big_end != null) {
            big_end.deleteState(BigState.HIDE)
            big_start.die(player,endPoint.id)
            return
        }
        startPoint.big = null
        endPoint.big = big_start
        big_start.point = endPoint
        this.gameMgr.sendBroadcast(Utils.getObj("big_move",{"start":data.start,"end":data.end}))
    }

    地灵_抹平(data:any,player:Player) {
        this.handlerMgr.spendAction(player,Config.COST_地灵_抹平)
        let startPoint = this.gameMgr.map_point.get(data.start)
        let endPoint = this.gameMgr.map_point.get(data.end)
        let big_start = startPoint.big
        big_start.actionOnce()
        let big_end = endPoint.big
        if(big_end != null) {
            big_end.deleteState(BigState.HIDE)
            big_start.die(player,endPoint.id)
            return
        }
        startPoint.big = null
        endPoint.big = big_start
        big_start.point = endPoint
        this.gameMgr.sendBroadcast(Utils.getObj("地灵_抹平",{"start":data.start,"end":data.end}))
        endPoint.changeTerrain(Terrain.KONG)
    }

    地灵_占据(data:any,player:Player) {
        this.handlerMgr.spendAction(player,Config.COST_地灵_占据)
        let startPoint = this.gameMgr.map_point.get(data.start)
        let endPoint = this.gameMgr.map_point.get(data.end)
        let big_start = startPoint.big
        big_start.actionOnce()
        let big_end = endPoint.big
        if(big_end != null) {
            big_end.attacked(player)
        }
        startPoint.big = null
        endPoint.big = big_start
        big_start.point = endPoint
        this.gameMgr.sendBroadcast(Utils.getObj("地灵_占据",{"start":data.start,"end":data.end}))
    }

}